package com.xbq.exceleditor.adapter

import android.net.Uri
import com.blankj.utilcode.constant.TimeConstants
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xbq.exceleditor.R
import com.xbq.exceleditor.databinding.ItemHomeJingxuanVideoBinding
import com.xbq.xbqsdk.net.officeeditor.vo.OfficeVideo
import com.xbq.xbqsdk.util.format.FormatUtils
import java.util.*
import javax.inject.Inject
import kotlin.random.Random

/**
 * Author: liaohaiping
 * Time: 2021-01-20
 * Description:
 */
class HomeJingxuanVideoAdapter @Inject constructor() :
    BaseQuickAdapter<OfficeVideo, BaseViewHolder>(R.layout.item_home_jingxuan_video) {

    override fun convert(holder: BaseViewHolder, item: OfficeVideo) {
        ItemHomeJingxuanVideoBinding.bind(holder.itemView).let {
            val random = Random(item.id)
            it.videoTitle.text = item.title
            val timeSpanByNow =
                com.blankj.utilcode.util.TimeUtils.getTimeSpanByNow(
                    Date(2021 - 1900, 0, 21),
                    TimeConstants.DAY
                )
            var increment = timeSpanByNow * random.nextInt(10, 100)
            val count = random.nextInt(1000, 1000000) + increment;
            it.videoDesc.text = "${FormatUtils.formatCount(count)}人学习过"
            val uri = Uri.parse(item.thumbnail)
            Glide.with(context)
                .load(uri)
                .into(it.videoImage)
        }
    }

}